<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>EMS单号生成器</title>
</head>
<body>
	<script>
		var KEYS = [ 8, 6, 4, 2, 3, 5, 9, 7 ];

		function makeEMSOrderNos(base, num) {
			var prefix = base.substring(0, 2);
			var center = base.substring(2, 11);
			var suffix = base.substring(11);
			var preNo = 0;
			preNo = parseInt(center.substring(0, 8));
			var results = [];
			for ( var i = 0; i < num; i++) {
				results[i] = [ prefix, makeOne(preNo + i + 1), suffix ]
						.join('');
			}
			return results;
		}

		function makeOne(preNo) {
			preNo = preNo.toString();
			var length = preNo.length;
			var lastNum = 0;
			for ( var i = 0; i < length; i++) {
				lastNum += KEYS[i] * (preNo.charAt(i) - '0');
			}
			lastNum = 11 - lastNum % 11;
			if (lastNum == 10) {
				lastNum = 0;
			} else if (lastNum == 11) {
				lastNum = 5;
			}
			return preNo + lastNum;
		}

		function make() {
			var base = document.getElementById('base').value;
			var num = document.getElementById('num').value;
			if (base.length != 13 || isNaN(num) || parseInt(num) < 1) {
				alert('请输入13位的基准运单号，如EE188718644CN，并且产生个数必须是大于0的整数');
				return;
			}
			var results = makeEMSOrderNos(base, num);
			document.getElementById('result').innerHTML = results.join('<br />');
		}
	</script>
	请输入11位的基准运单号，如EE188718644CN：<br />
	<input id="base" type="text" value="EE188718644CN" /><br /> 
	请输入要生成单号个数：<br />
	<input id="num" type="text" value="10" /><br />
	<input type="button" value="生成" onclick="make()" /><br />
	输出结果：<br />
	<div id="result"></div>
</body>
</html>